<?php namespace Admin\Controller; 

use Hdphp\Controller\Controller;
//后台登陆控制器
class LoginController extends Controller{
    //登录
    public function index(){
    	if(IS_POST){
    		//获得用户输入信息
	    	$username=Q('post.username');
	    	$password=md5(Q('post.password'));
			//判断用户名是否正确
			$model=new \Common\Model\Adminuser;
			$data = $model->where("username='{$username}'")->find();
			if(!$data) View::error('用户名密码错误！');
			if($data['password'] !=$password) View::error('用户名密码错误！');
			//保存登录时间
			$time=time();
			$model->where("username='{$username}'")->update(array('logintime'=>"$time"));
			//保存session
			$_SESSION['username']=$username;
			$_SESSION['uid']=$data['id'];
			View::success('登录成功！',U('Index/index'));
    	}
    	
		
       View::make();
    }
	
	//退出
	public function out(){
	    session_unset();
		session_destroy();
		View::success('退出成功！',U('index'));
	}
	
	
	
	
}
